package io;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;

import java.io.File;
import java.io.IOException;
import java.sql.Types;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @Author: ycy
 * @CreateDate: 2019/8/15 14:24
 */
public class FileDemo3 {


  /**
   * 台湾城市
   */
  private static final List<Integer> CHINA_OVER_SEA_CITYS_LIST = Lists.newArrayList(
          617, 720, 3844, 3845, 3846, 3847, 3848, 3849, 5152, 5383, 5589, 6954, 7203, 7523, 7524, 7570, 7613, 7614, 7662, 7805, 7808, 7809, 7810, 7811);

  public static final String OVERSEASTRAINT_SPERATOR = "_";


  public static void main(String[] args) {
    String cityNamelog = null;
    try {
      List<String> city = FileUtils.readLines(new File("D:\\Users\\yincy\\Desktop\\das需求\\交通\\火车票境外\\city.txt"), "UTF-8");
      Map<Integer, LocalCityPO> cityIdCityInfoMap = Maps.newHashMap();  //城市
      for (String cityStr : city) {
        String[] split = cityStr.split("\t",-2);
        int cityId = Integer.parseInt(split[0]);
        String cityName = split[1];
        cityNamelog = split[1];
        int countryId = Integer.parseInt(split[2]);
        String countryName = split[3];
        LocalCityPO localCityPO = new LocalCityPO();
        localCityPO.cityId = cityId;
        localCityPO.cityName = cityName;
        localCityPO.countryName = countryName;
        localCityPO.countryId = countryId;
        cityIdCityInfoMap.put(cityId, localCityPO);
      }


      List<String> train = FileUtils.readLines(new File("D:\\Users\\yincy\\Desktop\\das需求\\交通\\火车票境外\\src.txt"), "UTF-8");
      List<PeerOverSeasTrainPO> peeroverseastrain = Lists.newArrayList();
      for (String trainStr : train) {
        String[] split = trainStr.split("\t",-2);
        int country = Integer.parseInt(split[0]);
        int cityName = Integer.parseInt(split[1]);
        String tag = split[2];
        PeerOverSeasTrainPO peer = new PeerOverSeasTrainPO();
        peer.cityid = cityName;
        peer.CtripCountryId = country;
        peer.tag = tag;
        peeroverseastrain.add(peer);
      }

      Map<String, String> coutnryCityTagMap = Maps.newHashMap();

      for (PeerOverSeasTrainPO peerOverSeasTrainPO : peeroverseastrain) {
        LocalCityPO localCityPO = cityIdCityInfoMap.get(peerOverSeasTrainPO.cityid);
        //业务方国家 和 本地城市国家不匹配就放弃
        if (localCityPO == null || !(Objects.equals(localCityPO.countryId, peerOverSeasTrainPO.CtripCountryId)))
          continue;
        String tag = peerOverSeasTrainPO.tag;
        String cityName = localCityPO.cityName;
        String countryName = localCityPO.countryName;
        Integer countryId = localCityPO.countryId;
        Integer cityId = localCityPO.cityId;
        if (StringUtils.isNotBlank(cityName) && StringUtils.isNotBlank(countryName)
                && (countryId != 1 || (CHINA_OVER_SEA_CITYS_LIST.contains(cityId)))) { //国内只保留 台湾
          coutnryCityTagMap.put(countryName + OVERSEASTRAINT_SPERATOR + cityName, tag);//城市
          coutnryCityTagMap.put(countryName + OVERSEASTRAINT_SPERATOR, tag);//国家
        }
      }


      for (Map.Entry<String, String> entry : coutnryCityTagMap.entrySet()) {
//        System.out.println(entry.getKey() + "\t" + entry.getValue());
        if("日本_".equals(entry.getKey())){
          System.out.println(entry.getKey() + "\t" + entry.getValue());
        }
      }


    } catch (Exception e) {
      System.out.println(cityNamelog);
      e.printStackTrace();
    }


  }

}


class PeerOverSeasTrainPO {

  public Integer cityid;

  public Integer CtripCountryId;

  public String tag;

  public PeerOverSeasTrainPO() {
  }
}


class LocalCityPO {

  public Integer cityId;

  public String cityName;

  public Integer countryId;

  public String countryName;

  public LocalCityPO() {
  }


}